﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter06
{
    public class Code01
    {
        public static void Begin()
        {
            {
                double myVal;
                double multiplier = 5.3D;
                myVal = GetVal() * multiplier;
                Console.WriteLine(myVal);
                Console.ReadLine();
            }
            {
                string firstWord = GetWord("This is sentence.", 2);
                firstWord = GetWord("This is sentence.", 4, 3);
            }
            {
                int myNumber = 5;
                Console.WriteLine("myNumber = {0}", myNumber);
                ShowDouble(myNumber);
                Console.WriteLine("myNumber = {0}", myNumber);
                Console.ReadLine();
            }
            {
                int myNumber = 5;
                Console.WriteLine("myNumber = {0}", myNumber);
                myNumber = DoubleNum(myNumber);
                Console.WriteLine("myNumber = {0}", myNumber);
                Console.ReadLine();
            }
            {
                int myNumber = 5;
                Console.WriteLine("myNumber = {0}", myNumber);
                ShowDouble(ref myNumber);
                Console.WriteLine("myNumber = {0}", myNumber);
                Console.ReadLine();
            }
            {
                int[] myArray = new int[] { 1, 8, 3, 6, 2, 5, 9, 3, 0, 2 };
                int maxIndex;
                Console.WriteLine("The maximum vlaue in myArray is {0}", MaxValue(myArray, out maxIndex));
                Console.WriteLine("The first occurrence of this value is at element {0}", maxIndex + 1);
                Console.ReadLine();
            }

        }

        public static void BeginEx01()
        {
            Write();
        }

        public static void BeginEx02()
        {
            int[] myArray = { 1, 8, 3, 6, 2, 5, 9, 3, 0, 2 };
            int maxVal = MaxValue(myArray);
            Console.WriteLine("The maximun value in myArray is {0}", maxVal);
            Console.ReadLine();
        }

        public static void BeginEx03()
        {
            int sum = SumVals(1, 5, 2, 9, 8);
            Console.WriteLine("Summed Values = {0}", sum);
            Console.ReadLine();
        }

        private static int DoubleNum(int val)
        {
            val *= 2;
            return val;
        }

        private static string GetString()
        {
            return null;
        }

        private static double GetVal()
        {
            double checkVal = 4;
            if (checkVal < 5)
            {
                return 4.7D;
            }
            return 3.2D;
        }

        private static string GetWord(string param, params int[] count)
        {
            return param;
        }

        private static string GetWord(string param, int loacl, params int[] cont)
        {
            return param;
        }

        private static int MaxValue(int[] intArray)
        {
            int maxVal = intArray[0];
            for (int i = 1; i < intArray.Length; i++)
            {
                if (intArray[i] > maxVal)
                {
                    maxVal = intArray[i];
                }
            }
            return maxVal;
        }

        private static int MaxValue(int[] intArray, out int maxIndex)
        {
            int maxVal = intArray[0];
            maxIndex = 0;
            for (int i = 1; i < intArray.Length; i++)
            {
                if (intArray[i] > maxVal)
                {
                    maxVal = intArray[i];
                    maxIndex = i;
                }
            }
            return maxVal;
        }

        private static double MaxValue(double[] doubleArray)
        {
            double maxVal = doubleArray[0];
            for (int i = 1; i < doubleArray.Length; i++)
            {
                if (doubleArray[i] > maxVal)
                {
                    maxVal = doubleArray[i];
                }
            }
            return maxVal;
        }

        private static void MyFunciotn(string myString, double myDouble)
        {

        }

        private static double Product(double param1, double param2)
        {
            return param1 * param2;
        }

        private static int SumVals(params int[] vals)
        {
            int sum = 0;
            foreach (int val in vals)
            {
                sum += val;
            }
            return sum;
        }

        private static void ShowDouble(ref int val)
        {
            val *= 2;
            Console.WriteLine("val doubled = {0}", val);
        }

        private static void ShowDouble(int val)
        {
            val *= 2;
            Console.WriteLine("val doubled = {0}", val);
        }

        private static void Write()
        {
            Console.WriteLine("Text output from funcion.");
            Console.ReadLine();
        }
    }
}
